<template>
    <div>
<h3>登录页面</h3>
<table class="table table-bordered">
    <tbody>
        <tr>
            <td>登录名称</td>
            <td><input type="text" v-model="a.name"></td>
        </tr>
        <tr>
            <td>登录密码</td>
            <td><input type="password" v-model="a.pwd"></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="button" value="登录" @click="login"></td>
        </tr>
    </tbody>
</table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive}from 'vue'
import { useRoute,useRouter } from 'vue-router';
import axios from 'axios';
 const router=useRouter();

 let a=reactive({
    name:'',
    pwd:''
 })

 const login=()=>{
    if(a.name=="")
    {
        alert('登录名称不能为空');
        return;
    }
    if(a.pwd==''){
        alert("登录密码不能为空");
        return;
    }
    axios({
        method:'get',
        url:'/api/User/Login',
        params:a
    })
    .then((res)=>{
        console.log(res);
        if(res.data==-1){
            alert("名称错误");
            return;
        }
        if(res.data==-2){
            alert("密码错误");
            return;
        }
        alert('登录成功');
        router.push('/show');
    })
    .catch((err)=>{
        console.log(err);
    })
 }



</script>

<style scoped>

</style>